package auth

import (
	"github.com/astaxie/beego/orm"
	"time"
)
//权限表
type Auth struct {
	SysId int `orm:"pk;auto;description(自增ID)"`
	AuthName string `orm:"size(64);description(权限名称)"`
	UrlFor string  `orm:"null;size(256);description(菜单的url,一级菜单没有url,二级菜单才有)"`
	Pid int  `orm:"description(父级菜单的ID)"`
	PName string  `orm:"null;size(64);description(父级菜单名称)"`
	Desc string `orm:"null;size(256);description(描述)"`
	Icon string `orm:"null;size(256);description(左侧菜单列表图标)"`
	IsActive     int       `orm:"default(1);description(启用状态 1=正常 2=停用)"`
	IsDelete     int       `orm:"default(0);description(删除状态 0=正常 1=删除)"`
	Weight int `orm:"default(0);description(权重，主要是为了菜单排序)"`
	UpdatedTime  time.Time `orm:"null;auto_now;type(datetime);description(更新时间)"`
	CreateTime   time.Time `orm:"auto_now_add;type(datetime);description(创建时间)"`
	Role []*Role `orm:"reverse(many);description(多对多,和角色表反向关系)"`
}
//角色表
type Role struct {
	SysId int `orm:"pk;auto;description(自增ID)"`
	RoleName string `orm:"size(128);description(角色名称)"`
	Desc string `orm:"size(256);description(角色描述)"`
	IsActive     int       `orm:"default(1);description(启用状态 1=正常 2=停用)"`
	IsDelete     int       `orm:"default(0);description(删除状态 0=正常 1=删除)"`
	UpdatedTime  time.Time `orm:"null;auto_now;type(datetime);description(更新时间)"`
	CreateTime   time.Time `orm:"auto_now_add;type(datetime);description(创建时间)"`
	Auth []*Auth `orm:"rel(m2m);description(多对多,和权限表正向关系)"`
	User []*User `orm:"rel(m2m);description(多对多,和用户表正向关系)"`
}
// 用户表
type User struct {
	SysId        int       `orm:"pk;auto;description(自增ID)"`
	JobId		 string    `orm:"column(job_id);size(64);description(员工工号)"`
	UserName     string    `orm:"unique;column(user_name);size(64);description(用户账号)"`
	NickName     string    `orm:"column(nick_name);size(64);description(用户昵称)"`
	PassWord     string    `orm:"size(64);description(用户密码)"`
	Age          int       `orm:"null;description(用户年龄)"`
	Gender       int       `orm:"null;default(1);description(性别: 1=男 2=女 3=未知)"`
	Phone        int64     `orm:"null;description(用户手机号码)"`
	Addr         string    `orm:"null;size(255);description(用户联系地址)"`
	Email        string    `orm:"null;size(64);description(用户邮件)"`
	CardId       string    `orm:"null;size(64);description(身份证号)"`
	HeadPortrait string    `orm:"null;size(255);description(用户头像)"`
	IsActive     int       `orm:"default(1);description(启用状态 1=正常 2=停用)"`
	IsDelete     int       `orm:"default(0);description(删除状态 0=正常 1=删除)"`
	UpdatedTime  time.Time `orm:"null;auto_now;type(datetime);description(更新时间)"`
	CreateTime   time.Time `orm:"auto_now_add;type(datetime);description(创建时间)"`
	Role []*Role `orm:"reverse(many)"`
	CarsApply []*CarsApply `orm:"reverse(many)"`   // 一人可以申请多辆车
	MessageNotify []*MessageNotify `orm:"reverse(many)"` // 一人对多
}


//车辆品牌，有表关联依赖需要放到一个modes文件里面，不然会报重复循环引入
type CarBrand struct{
	SysId int `orm:"pk;auto;description(自增ID)"`
	BrandName string `orm:"size(64);description(品牌名称)"`
	BrandDesc string `orm:"size(255);description(品牌描述)"`
	Cars []*Cars `orm:"reverse(many)"` //车辆对应数据一对多
	IsActive int `orm:"default(1);description(启用状态 1=正常 2=停用)"`
	IsDelete int `orm:"default(0);description(删除状态 0=正常 1=删除)"`
	CreateTime time.Time `orm:"description(创建时间);type(datetime);auto_now"`

}

//车辆列表，一辆车可以被多人申请
type Cars struct{
	SysId int `orm:"pk;auto;description(自增ID)"`
	CarName string `orm:"size(64);description(车辆名称)"`
	Status int `orm:"default(1);description(车辆状态 1=可借 2=已借出)"`
	CarBrand *CarBrand `orm:"rel(fk);description(车辆品牌外键)"`  //对应html里面的值，如果这里带了CarBrand表名里面就不用带
	CarsApply []*CarsApply `orm:"reverse(many)"` // 车辆申请对应数据一对多
	IsActive int `orm:"default(1);description(启用状态 1=正常 2=停用)"`
	IsDelete int `orm:"default(0);description(删除状态 0=正常 1=删除)"`
	CreateTime time.Time `orm:"description(创建时间);type(datetime);auto_now"`
}


//车辆申请，审核，支持一个用户借多辆车
type CarsApply struct{
	SysId int `orm:"pk;auto;description(自增ID)"`
	User *User `orm:"rel(fk);description(用户表外键)"`
	Cars *Cars `orm:"rel(fk);description(车辆表外键)"`
	Reason string `orm:"size(255);description(申请理由)"`
	Destination string `orm:"size(255);description(目的地)"`
	ReturnDate time.Time `orm:"description(归还日期);type(datetime);auto_now"`
	ReturnStatus int `orm:"default(0);description(归还状态 1=已归还 2=未归还)"`
	AuditStatus int `orm:"default(3);description(审核状态 1=同意 2=不同意 3=未审批)"`
	AuditOption string `orm:"size(255);description(审批意见)"`
	IsActive int `orm:"default(1);description(启用状态 1=正常 2=停用)"`
	IsDelete int `orm:"default(0);description(删除状态 0=正常 1=删除)"`
	CreateTime time.Time `orm:"description(创建时间);type(datetime);auto_now"`
	NotifyTag int `orm:"description(1:已发送通知，0：未发送通知);default(0)"`
}

// 消息通知
type MessageNotify struct {
	Id int `orm:"pk;auto"`
	Flag int `orm:"description(1:车辆逾期，2:所有通知);default(1)"`
	Title string `orm:"size(128);description(消息标题)"`
	Content string `orm:"type(text);description(消息内容)"`
	User *User `orm:"rel(fk);desription(用户外键)"`
	ReadTag int `orm:"description(状态：1=已读，0=未读)"`

}


// 自定义模型对应数据库里的表名
func (u *User) TableName() string {
	return "sys_user"
}

func (u *Auth) TableName() string {
	// 返回表名
	return "sys_auth"
}

func (u *Role) TableName() string {
	// 返回表名
	return "sys_role"
}

func (u *CarBrand) TableName() string {
	// 返回表名，车辆品牌表
	return "sys_cars_brand"
}

func (u *Cars) TableName() string {
	// 返回表名,车辆列表
	return "sys_cars"
}

func (u *CarsApply) TableName() string {
	// 返回表名，车辆审核表
	return "sys_cars_apply"
}

func (u *MessageNotify) TableName() string {
	// 返回表名，消息通知表
	return "sys_message_notify"
}


// 将结构体注册为orm模型
func init() {
	orm.RegisterModel(
		new(Auth),
		new(Role),
		new(User),
		new(CarBrand),
		new(Cars),
		new(CarsApply),
		new(MessageNotify))
}
